package game;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
//
//	Plat 01 - 100% 
//	Plat 02 - 75%
//  Plat 03 - Aprox 25%
//
public class Plataforma extends Sprite {
	float VelX = -180f;
	float VelY;
	ArrayList<Quadrado> plat = new ArrayList<Quadrado>();
	int numQuad;
	
	boolean willFall = true;
	boolean falling = false;
	
	
	public Plataforma(BufferedImage bg, float x, float y, float tx, float ty, int numQuad) {
		super(bg, x, y, tx, ty);
		this.numQuad = numQuad;
		int a = 0;
		int b=0;
		int qtdTerra = (600-(int)Y)/16;
		TX = numQuad*16;
		TY = 16+(qtdTerra*16)+16;
		
		//System.out.println(qtdTerra);
		for(int i =0; i< numQuad; i++){
			
			Quadrado quad;
			if(i == 0){
				 quad = new Quadrado(Tela01.tilePlat, X+a, Y+b, 16, 16,0);
			}else{
				if(i==numQuad-1){
					 quad = new Quadrado(Tela01.tilePlat, X+a, Y+b, 16, 16,2);
				}
				else{
					quad = new Quadrado(Tela01.tilePlat, X+a, Y+b, 16, 16,1);
				}
			}
			

			plat.add(quad);
			a+=16;
			//System.out.println(quad.pos+"  "+i);
		}
		a=0;
		for(int j=0;j< qtdTerra+1;j++){
			b+=16;
			a=0;
			for(int i =0; i< numQuad; i++){
				
				Quadrado quad;
				if(i == 0){
					 quad = new Quadrado(Tela01.tilePlat, X+a, Y+b, 16, 16,3);
				}else{
					if(i==numQuad-1){
						 quad = new Quadrado(Tela01.tilePlat, X+a, Y+b, 16, 16,5);
					}
					else{
						quad = new Quadrado(Tela01.tilePlat, X+a, Y+b, 16, 16,4);
					}
				}
				plat.add(quad);
				a+=16;
				
			}
		}
		
	}



	
	@Override
	public void Simulase(long diffTempo) {
		// TODO Auto-generated method stub
		
		//VelX += -60f*diffTempo/1000;
		X += VelX*diffTempo/1000;
		
		for(int i =0; i< plat.size(); i++){
			plat.get(i).X += VelX*diffTempo/1000;

		}
		if(this.X+this.TX <0){
			//System.out.println("Removeu");
			Tela01.platList.remove(this);
		}
		
		if(falling){
			platFall(diffTempo);
		}
	}

	@Override
	public void Desenha(Graphics2D dbg) {
		super.Desenha(dbg);
		dbg.setColor(Color.red);
		//dbg.fillRect((int)X, (int)Y, (int)TX, (int)TY);
		for(int i=0; i< plat.size();i++){
			plat.get(i).Desenha(dbg);
			
		}
		
	}
	
	public void platFall(long diffTempo){
		Y += 60f*diffTempo/1000;
		for(int i =0; i< plat.size(); i++){
			plat.get(i).Y += 60f*diffTempo/1000;

		}
	}

}

